/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.sd.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sd.common.constants.FileCabinetRecordEnum;
import com.jeesite.modules.sd.entity.FileCabinetRecord;
import com.jeesite.modules.sd.service.FileCabinetRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 系统与文件柜交互记录表Controller
 *
 * @author linyh
 * @version 2020-07-29
 */
@Controller
@RequestMapping(value = "/sd/fileCabinetRecord")
public class FileCabinetRecordController extends BaseController {

    @Autowired
    private FileCabinetRecordService fileCabinetRecordService;

    /**
     * 获取数据
     */
    @ModelAttribute
    public FileCabinetRecord get(String id, boolean isNewRecord) {
        return fileCabinetRecordService.get(id, isNewRecord);
    }

    /**
     * 查询列表
     */
    @RequestMapping(value = {"list", ""})
    public String list(FileCabinetRecord fileCabinetRecord, Model model) {
        model.addAttribute("fileCabinetRecord", fileCabinetRecord);
        return "modules/sd/fileCabinetRecordList";
    }

    /**
     * 查询列表数据
     */
    @RequestMapping(value = "listData")
    @ResponseBody
    public Page<FileCabinetRecord> listData(FileCabinetRecord fileCabinetRecord, HttpServletRequest request, HttpServletResponse response) {
        fileCabinetRecord.setPage(new Page<>(request, response));
        Page<FileCabinetRecord> page = fileCabinetRecordService.findPage(fileCabinetRecord);
        return page;
    }

    /**
     * 查询列表数据
     */
    @RequestMapping(value = "selectStatusListData")
    @ResponseBody
    public Page<FileCabinetRecord> selectStatusListData(FileCabinetRecord fileCabinetRecord, HttpServletRequest request, HttpServletResponse response) {
        fileCabinetRecord.setPage(new Page<>(request, response));
        fileCabinetRecord.setResponseStatus(FileCabinetRecordEnum.STATUS_SUCCESS.getValue());
        fileCabinetRecord.setOperation(FileCabinetRecordEnum.NOT_OPERATING.getValue());
        String[] queryTypeIn = {FileCabinetRecordEnum.TYPE_USER_FACE_RESULT.getValue()
                ,FileCabinetRecordEnum.TYPE_CABINET_CLOSE_RESULT.getValue()};
        fileCabinetRecord.getSqlMap().getWhere().and("response_type", QueryType.NOT_IN, queryTypeIn);
        Page<FileCabinetRecord> page = fileCabinetRecordService.findPage(fileCabinetRecord);
        return page;
    }

    /**
     * 查看编辑表单
     */
    @RequestMapping(value = "form")
    public String form(FileCabinetRecord fileCabinetRecord, Model model) {
        model.addAttribute("fileCabinetRecord", fileCabinetRecord);
        return "modules/sd/fileCabinetRecordForm";
    }

    /**
     * 保存数据
     */
    @PostMapping(value = "save")
    @ResponseBody
    public String save(@Validated FileCabinetRecord fileCabinetRecord) {
        fileCabinetRecordService.save(fileCabinetRecord);
        return renderResult(Global.TRUE, text("保存系统与文件柜交互记录表成功！"));
    }
}